﻿#-------------------------------------------------------------------------------
# Name:        модуль1
# Purpose:
#
# Author:      GaiveR
#
# Created:     03.09.2011
# Copyright:   (c) ASM-Team 2011
# Licence:     Private
#-------------------------------------------------------------------------------
#!/usr/bin/env python

from pgu import gui

class MainGui(gui.Desktop):
    #gameAreaHeight = 500
    menuAreaHeight = 100
    gameArea = None
    menuArea = None

    def __init__(self, disp):
        gui.Desktop.__init__(self)
        self.disp = disp

        # create menu areas
        self.main_menu_area = MainMenu()
        self.tower_menu_area = TowerMenu()

        # Setup the 'game' area where the action takes place
        self.gameAreaHeight = disp.get_height() - self.menuAreaHeight
        self.gameArea = gui.Widget(width=disp.get_width(),
                                   height=self.gameAreaHeight)
        # Setup the gui area
        self.menuArea = self.main_menu_area

        tbl = gui.Table(height=disp.get_height())
        tbl.tr()
        tbl.td(self.gameArea, valign=-1)
        tbl.tr()
        tbl.td(self.menuArea)
        self.tbl = tbl

        self.init(tbl, disp)
        ##

    def showMainMenu(self):
        self.setActiveMenu(self.main_menu_area)
    def showTowerMenu(self):
        self.setActiveMenu(self.tower_menu_area)

    def setActiveMenu(self, menu):
        if menu is self.menuArea:
            return
        self.tbl.remove(self.menuArea)
        self.menuArea = menu
        self.tbl.td(self.menuArea)



    def get_render_area(self):
        return self.gameArea.get_abs_rect()

################################################################################

class MainMenu(gui.Table):
    """
    Основная панель действий. Нет выбранных объектов.
    """
    def __init__(self, **params):
        gui.Table.__init__(self, **params)

        def fullscreen_changed(btn):
            #pygame.display.toggle_fullscreen()
            print("TOGGLE FULLSCREEN")

        def newtower_click(tower_id):
            game_location.newTowerBegin(tower_id)

        fg = (255,0,255)

        btn = gui.Button('Simple tower(u)')
        btn.connect(gui.CLICK, newtower_click, 1)
        self.add(btn, row=1)

        btn = gui.Button('Splash tower(i)')
        btn.connect(gui.CLICK, newtower_click, 2)
        self.add(btn, row=1)

        btn = gui.Button('Air tower(o)')
        btn.connect(gui.CLICK, newtower_click, 3)
        self.add(btn, row=2)

        btn = gui.Button('Aura tower(p)')
        btn.connect(gui.CLICK, newtower_click, 4)
        self.add(btn, row=2)

##        self.tr()
##        btn = gui.Switch(value=False, name='fullscreen')
##        btn.connect(gui.CHANGE, fullscreen_changed, btn)
##        self.td(gui.Label('full screen'))
##        self.td(btn)


class TowerMenu(gui.Table):
    """
    Панель действий башни.
    """
    def __init__(self, **params):
        gui.Table.__init__(self,**params)

        def update_click(button):
            print('update button clicked')

        self.clear()
        self.tr()
        self.add(gui.Label('tower selected'))
        self.tr()

        btn = gui.Button('Update')
        btn.connect(gui.CLICK, update_click, btn)
        self.add(btn)

################################################################################

def initApp(disp, gl):
    global app, game_location
    app = MainGui(disp)
    game_location = gl
    ##